﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using _430GroupProject;

namespace WebClient.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string userID = UserName.Text;
            string password = Password.Text;

            //Encrypt Password before sending it over to service.
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] data = System.Text.Encoding.ASCII.GetBytes(password);
            data = x.ComputeHash(data);
            String md5Hash = System.Text.Encoding.ASCII.GetString(data);



            User res = Master.Proxy.getUserLogon(userID, md5Hash);
            if (Master.ut.hasErrors(res))
            {
                ErrorText.Text = res.Error.Header + ", " + res.Error.Message;
                ErrorPanel.Visible = true;
                UpdateAjax.Update();
                
            }else{
                Session["user"] = res;
                Response.Redirect("/PharosClient/HomePage.aspx");
              }
             
             

            

        }

        protected void ErrorClose_Click(object sender, EventArgs e)
        {
            ErrorPanel.Visible = false;
        }

    }
}
